﻿<%@ Page Title="mobileSendInfo" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="lcgps.Web.mobileSendInfo.List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6a5e0746feee514e8bb7b3f468a626d1">
    </script>
    <script src="../Script/TextIconOverlay_min.js"></script>
    <script src="../Script/MarkerClusterer_min.js"></script> 
    <style type="text/css">
        #mymap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>

    <script type="text/javascript">
        var ptc;
        var pth;
        var pn;
        var map;
        var pid = "";
        var pcid = "";
        var mid = "";
        var timeid;
        var keyid = "";
        var purchaseid = "";
        var actionUrl = 'GetMobile.ashx';
        var markerClusterer;
        var markers = [];
        //var home = new BMap.Icon('../images/house.png', new BMap.Size(16, 16), { anchor: new BMap.Size(8, 16) });

        $(function () {
            InitGird();
            InitMap();
        });
        function InitMap() {
            map = new BMap.Map("mymap");          // 创建地图实例 
            map.addControl(new BMap.MapTypeControl());   //添加地图类型控件    
            map.centerAndZoom(new BMap.Point(115.986869, 36.455829),8);
            //map.centerAndZoom("聊城", 11);
            map.enableScrollWheelZoom(true);
            var top_left_control = new BMap.ScaleControl({ anchor: BMAP_ANCHOR_TOP_LEFT });// 左上角，添加比例尺
            var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
            map.addControl(top_left_control);
            map.addControl(top_left_navigation);
        }        
        function addClickHandler(content, marker) {
            marker.addEventListener("click", function (e) {
                openInfo(content, e);

            }
            );
        }
        function openInfo(content,e) {
            var p = e.target;
            var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);            
            var infoWindow = new BMap.InfoWindow(content);
            map.openInfoWindow(infoWindow, point); //开启信息窗口            
        }
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '订单照片列表', //表格标题
                url: 'GetMobile.ashx', //请求数据的页面
                sortName: 'sendTime', //排序字段
                idField: '', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠                
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                method: 'post',
                checkOnSelect: false,
                singleSelect:true,
                columns: [[
                 { field: 'ckb', checkbox: true },
                {
                    title: '订单号', field: 'purchaseid', width: 100, formatter: function (value, row, index) {
                        return '<a  onclick="showawsinfectInfo(\'' +value + '\')">' + value + '</a>';

                    }
                },
                { title: '发送人', field: 'user_name', width: 50 },
				{ title: '发送时间', field: 'sendTime', width: 180 }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                onClickRow: function (rowIndex, rowData) {
                    map.clearOverlays();
                    if (markers.length > 0) {
                        if (markerClusterer)
                        markerClusterer.removeMarkers(markers);
                        markers = [];
                    }
                    var ggPoint = new BMap.Point(rowData.GPSLongitude, rowData.GPSLatitude);
                    keyid = rowData.KeyId;
                    purchaseid = rowData.purchaseid;
                    var marker = new BMap.Marker(ggPoint);
                    var content = "<a onclick='showawsinfectInfo(\"" + purchaseid + "\")'><img style='margin:4px'  src='GetMobile.ashx?action=pic&KeyId=" + keyid + "' width='300' height='200' /></a>";
                    map.addOverlay(marker);       
                    addClickHandler(content, marker);                    
                    map.centerAndZoom(ggPoint,19);
                },
                onLoadSuccess: function (data) {
                    data_info = [];
                    map.clearOverlays();
                    $.each(data.rows, function (k, v) {
                        data_info.push({ "KeyId": v["KeyId"],"purchaseid":v["purchaseid"], "lng": v["GPSLongitude"], "lat": v["GPSLatitude"] });

                    });                    
                    var marker;
                    pt = "";
                    if (markers.length > 0) {
                        markerClusterer.removeMarkers(markers);
                        markers = [];
                    }

                    for (var i = 0; i < data_info.length; i++) {                   
                        pt = new BMap.Point(data_info[i].lng, data_info[i].lat);                    
                        marker = new BMap.Marker(pt);
                        var content = "<a onclick='showawsinfectInfo(\"" + data_info[i].purchaseid + "\")'><img style='margin:4px' src='GetMobile.ashx?action=pic&KeyId=" + data_info[i].KeyId + "' width='300' height='200'  /></a>";
                        map.addOverlay(marker);
                        markers.push(marker);
                        addClickHandler(content, marker);
                    }
                    
                    markerClusterer = new BMapLib.MarkerClusterer(map, { markers: markers });//对地图扩大缩小后会都所有的点全显示出来。
                    map.centerAndZoom(marker, 18);
                },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });
        }
        function getQueryParams(queryParams) {
            var StartTime = $("#StartTime").datebox("getValue");
            var EndTime = $("#EndTime").datebox("getValue");            
            var pcid = $("#pcid").val();            
            queryParams.StartTime = StartTime;
            queryParams.EndTime = EndTime;            
            queryParams.pcid = pcid;            
            return queryParams;
        }

        //增加查询参数，重新加载表格  
        function reloadgrid() {
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');
        }
        function removeUser() {
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetMobile.ashx?KeyId=' + row.KeyId+ '&action=delete',
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {                                    
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    $('#tt').datagrid('reload');
                                }
                                else if ((result.indexOf("F") == 0)) {
                                    $.messager.alert("提示", "删除失败，请重新操作！", "info");
                                    return;
                                }
                                else if ((result.indexOf("L") == 0)) {
                                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                    top.location = '/index.aspx';
                                    return;
                                }
                            }
                        });
                    }
                })
            }
        }
        function showawsinfectInfo(id) {
            top.addTab('订单号：'+id, '/gpsinfo/listmaterial.aspx?pcid=' + id);
        }        

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="easyui-layout" style="width: 100%; height: 100%;" id="mycon">
        <div region="west" split="true" style="width:400px; overflow: auto" id="west">
            <table id="tt"></table>
            <div id="tab_toolbar" style="padding: 4px;">
                <table cellpadding="0" cellspacing="0" style="width: 100%">
                    <tr>

                        <td style="padding-left: 2px">
                            <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>
                        时间从:  
           <input id="StartTime" class="easyui-datebox" style="width: 100px" />
                            到:  
           <input id="EndTime" class="easyui-datebox" style="width: 100px" />
                            
                        </td>
                    </tr>
                    <tr>
                        <td>
                            订单号：<input type="text" id="pcid" name="pcid" />
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid()">查找</a>
                        </td>
                    </tr>

                </table>
            </div>

        </div>
        <div region="center" style="background: #eee; overflow: auto">
            <div style="position: relative; width: 100%; height: 100%;">
                <div id="mymap"></div>
            </div>
        </div>
    </div>
    <form id="fm" method="post">
        <input type="hidden" id="pid" name="pid" />
        <input type="hidden" id="purchaseid" name="purchaseid" />
        <input type="hidden" id="mid" name="mid" />
    </form>
</asp:Content>
